﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Download
{
    public class DownBase
    {
        public DownBase()
        {

        }
        private WebClient wc = new WebClient();

        public String DownString(string url)
        {
            try
            {
                Stream st = wc.OpenRead(url);
                StreamReader sr = new StreamReader(st, Encoding.Default);
                string res = sr.ReadToEnd();
                sr.Close();
                st.Close();
                return res;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return "";
            }
        }

        public String DownString(string url,Encoding enc)
        {
            try
            {
                Stream st = wc.OpenRead(url);
                StreamReader sr = new StreamReader(st, enc);
                string res = sr.ReadToEnd();
                sr.Close();
                st.Close();
                return res;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return "";
            }
        }


    }
}
